import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  UpdateDateColumn,
  ManyToMany,
  JoinTable,
} from 'typeorm';
import { Role } from './role.entity';

@Entity()
export class User {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({
    length: 50,
    comment: '用户名',
  })
  username: string;

  @Column({
    length: 50,
    comment: '密码',
  })
  password: string;

  @Column({
    name: 'nick_name',
    length: 50,
    comment: '昵称',
  })
  nickName: string;

  @Column({
    length: 50,
    comment: '邮箱',
  })
  email: string;

  @Column({ name: 'head_pic', length: 255, comment: '头像', nullable: true })
  headPic: string;

  @Column({
    name: 'phone_number',
    length: 20,
    comment: '手机号',
  })
  phoneNumber: string;

  @Column({
    name: 'is_admin',
    default: 0,
    comment: '是否管理员',
  })
  isAdmin: number;

  @Column({
    name: 'is_frozen',
    default: 0,
    comment: '是否冻结',
  })
  isFrozen: number;

  @CreateDateColumn()
  createdAt: Date;

  @UpdateDateColumn()
  updatedAt: Date;

  @ManyToMany(() => Role)
  @JoinTable({
    name: 'user_roles',
  })
  roles: Role[];
}
